package com.fdm.controller;

import java.io.IOException;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.fdm.model.BankAccountOutputVO;

public class DisplayManager implements _DisplayManager{

	private String resultJSP;
	private HttpServletRequest request;
	private HttpServletResponse response;
	
	public DisplayManager(){}
	
	public DisplayManager(HttpServletRequest request,
			HttpServletResponse response){
		this.setHttpServletRequest(request);
		this.setHttpServletResponse(response);
	}
	
	@Override
	public void displayOutput(BankAccountOutputVO output) 
			throws ServletException, IOException {
		RequestDispatcher view = request.getRequestDispatcher(resultJSP);
		request.setAttribute("output", output);
		view.forward(request, response);
	}

	@Override
	public void setResultJSP(String resultJSP) {
		this.resultJSP = resultJSP;
	}

	@Override
	public void setHttpServletRequest(HttpServletRequest request) {
		this.request = request;
	}

	@Override
	public void setHttpServletResponse(HttpServletResponse response) {
		this.response = response;
	}

	@Override
	public void displayError(String errorMessage) 
			throws ServletException, IOException {
		this.setResultJSP("/message.jsp");
		RequestDispatcher view = request.getRequestDispatcher(resultJSP);
		request.setAttribute("title", "Error Found");
		request.setAttribute("message", errorMessage);
		view.forward(request, response);
	}

	@Override
	public void displayList(List<BankAccountOutputVO> outputList) 
			throws ServletException, IOException {
		RequestDispatcher view = request.getRequestDispatcher(resultJSP);
		request.setAttribute("outputList", outputList);
		view.forward(request, response);
	}

	@Override
	public void setAttributes(String JSP, HttpServletRequest request,
			HttpServletResponse response) {
		this.setHttpServletRequest(request);
		this.setHttpServletResponse(response);
		this.setResultJSP(JSP);
	}

}
